import Vue from 'vue';
import Router from 'vue-router'  // 引入vue-router
Vue.use(Router);

export const constantRouterMap = [
    {path: "/", redirect: "/index"},
    {
        path: "/login",
        name: "login",
        component: () => import("../views/Login")
    },
    {
        path: "/home",
        name: "home",
        component: () => import('../views/Home'),
        children: [
            /* 首页 */
            {
                path: "/index",
                name: "index",
                component: () => import("../views/index"),
                meta: {
                    keepAlive: true
                }
            },
            /* 工作流 */
            {
                path: "/apply",
                name: "apply",
                component: () => import("../views/flow/apply"),
                meta: {
                    keepAlive: true
                }
            },
            {
                path: "/backlog",
                name: "backlog",
                component: () => import("../views/flow/backlog"),
                meta: {
                    keepAlive: true
                }
            },
            {
                path: "/design",
                name: "design",
                component: () => import("../views/flow/design"),
                meta: {
                    keepAlive: true
                }
            },
            {
                path: "/finished",
                name: "finished",
                component: () => import("../views/flow/finished"),
                meta: {
                    keepAlive: true
                }
            },
            {
                path: "/manage",
                name: "manage",
                component: () => import("../views/flow/manage"),
                meta: {
                    keepAlive: true
                }
            },
            {
                path: "/records",
                name: "records",
                component: () => import("../views/flow/records/index"),
                meta: {
                    keepAlive: false
                }
            },
            {
                path: "/execute",
                name: "execute",
                component: () => import("../views/flow/execute"),
                meta: {
                    keepAlive: false
                }
            },
            {
                path: "/designForm",
                name: "designForm",
                component: () => import("../views/form/designform"),
                meta: {
                    keepAlive: false
                }
            },
            {
                path: "/editform",
                name: "editform",
                component: () => import("../views/form/editform"),
                meta: {
                    keepAlive: false
                }
            },
            /* 用户 */
            {
                path: "/user",
                name: "user",
                component: () => import("../views/user/user"),
                meta: {
                    keepAlive: true
                }
            },
            {
                path: "/role",
                name: "role",
                component: () => import("../views/user/role"),
                meta: {
                    keepAlive: true
                }
            },
            {
                path: "/permission",
                name: "permission",
                component: () => import("../views/user/permission"),
                meta: {
                    keepAlive: true
                }
            },
            {
                path: "/depart",
                name: "depart",
                component: () => import("../views/user/depart"),
                meta: {
                    keepAlive: true
                }
            },
            /* 代码生成器 */
            {
                path: "/generate",
                name: "generate",
                component: () => import("../views/code/generate"),
                meta: {
                    keepAlive: true
                }
            },
            /* 系统 */
            {
                path: "/server",
                name: "server",
                component: () => import("../views/system/server"),
                meta: {
                    keepAlive: true
                }
            },
            {
                path: "/dict",
                name: "dict",
                component: () => import("../views/system/dict"),
                meta: {
                    keepAlive: true
                }
            },
            {
                path: "/quartz",
                name: "quartz",
                component: () => import("../views/system/quartz"),
                meta: {
                    keepAlive: true
                }
            },
            {
                path: "/loginlog",
                name: "loginlog",
                component: () => import("../views/system/loginlog"),
                meta: {
                    keepAlive: true
                }
            }
        ]
    },
    {
        path: "/modeler",
        name: "modeler",
        component: () => import("../views/flow/modeler")
    },
    // {
    //     path: '*',
    //     name: 'err404',
    //     component: () => import("../views/components/Err404")
    // }
]

// const VueRouterPush = Router.prototype.push
// Router.prototype.push = function push(to) {
//     return VueRouterPush.call(this, to).catch(err => err)
// }

// 导出路由
export default new Router({
    mode: 'history',
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRouterMap
})
